<template>
  <view class="exchange-layout">
    <my-header title="拒提"></my-header>
    <my-content class="content">
      <view style="visibility: hidden">1</view>
      <view class="goods_box" :style="{backgroundImage: `url(https://www.dingxians.cn/upload/images/box/bg-box-${orderData.level_id}.png)`}">
        <!--      <view class="goods_level" :style="{ background: orderData.level_color }">{{ orderData.level_name }}</view>-->
        <view class="goods_info">
          <view
            class="goods-image-bg"
          >
            <image
              mode="widthFix"
              class="goods_image"
              :src="orderData.blind_box_prize_image"
            ></image>
          </view>
          <view class="goods_item">
            <view class="goods_name">{{ orderData.blind_box_prize_name }}</view>
            <view class="goods_price_num-box">
              <view class="goods_price">
                <view>拒提价：</view>
                <view>{{ orderData.recovery_price }}</view>
                <image
                  class="gold"
                  mode="widthFix"
                  src="https://www.dingxians.cn/upload/images/shop/money.png"
                ></image>
              </view>
              <view class="goods_num">
                <my-number-box class="number-box" v-model="orderData.num" :max="orderData.num" :min="1"></my-number-box>
              </view>
            </view>
          </view>
        </view>
      </view>

      <view class="exchange item-bg" v-if="rule">
        <rich-text :nodes="rule" class="exchange"></rich-text>
      </view>
      <view style="flex: 1;"></view>

      <view class="bottom">
        <view class="bottom_text">
          <view class="bottom_text_num">共<span style="color: #DED000">{{ orderData.num }}</span>件 |</view>
          <view>合计：</view>
          <view class="bottom_text_amount">{{ totalAmount }}</view>
          <image class="gold" mode="widthFix" src="https://www.dingxians.cn/upload/20230830/64ef5fa303c81.png"></image>
        </view>
        <view class="exchange_btn btn-primary" v-if="!exchangeStatus" @click="exchange()">立即拒提</view>
        <view class="exchange_btn btn-primary none" v-else>立即拒提</view>
      </view>
    </my-content>

    <my-alert-dialog ref="alertDialog" title="提示" content="确定要拒提嘛？" @confirm="onConfirm"
                     @cancel="onCancel"></my-alert-dialog>
  </view>
</template>

<script>
import api from '../../api/index.js'
import box from '@/mixins/box'

export default {
  mixins: [box],
  data() {
    return {
      orderData: {
        price: '',
        recovery_price: '',
        num: 1,
        level_name: '',
      },
      id: '',
      rule: '',
      exchangeStatus: false,
      type: 0,
    }
  },
  computed: {
    totalAmount() {
      return (this.orderData.recovery_price * this.orderData.num).toFixed(2)
    },
  },
  onLoad(option) {
    this.id = option.id
    this.type = +option.type
    this.getGoods()
  },
  onShow() {
    this.exchangeStatus = false
  },
  methods: {
    onConfirm() {
      uni.showLoading({
        title: '拒提中',
      })
      this.exchangeStatus = true
      let promise
      if (this.type === 1) {
        promise = api.welfareHouses.exchange({ id: this.id })
      } else if (this.type === 0) {
        promise = api.blindBoxOrderPrizes.exchange({ params: this.id + ':' + this.orderData.num })
      } else if (this.type === 2) {
        promise = api.towers.exchange({ params: this.id + ':' + this.orderData.num })
      } else if (this.type === 3) {
        promise = api.compounds.exchange({ params: this.id + ':' + this.orderData.num })
      }
      promise
        .then((res) => {
          if (res.code === 200) {
            uni.hideLoading()
            this.show('拒提成功')
            setTimeout(() => {
              uni.navigateBack()
            }, 500)
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    onCancel() {

    },
    getGoods() {
      uni.showLoading({
        title: '数据加载中',
      })
      let promise
      if (this.type === 1) {
        promise = api.welfareHouses.show(this.id)
      } else if (this.type === 0) {
        promise = api.blindBoxOrderPrizes.show(this.id)
      } else if (this.type === 2) {
        promise = api.towers.show(this.id)
      } else if (this.type === 3) {
        promise = api.compounds.show(this.id)
      }
      promise
        .then((res) => {
          if (res.code === 200) {
            uni.hideLoading()
            this.orderData = res.data.data
            this.rule = res.data.rule
          }
        })
        .catch((error) => {
          console.log(error)
        })
    },
    exchange() {
      this.$refs.alertDialog.show()
      /*uni.showModal({
        title: '提示',
        content: `确定拒提吗？`,
        success: (result) => {
          if (result.confirm) {

          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        },
      })*/
    },
  },
}
</script>

<style lang="scss" scoped>
.exchange-layout {
  background: #141414;
  height: 100%;
  min-height: 100vh;
}

.content {
  .goods_box {
    display: flex;
    flex-direction: column;
    margin: 0 auto;
    width: 710rpx;
    height: 460rpx;
    border-radius: 5rpx;
    background-size: 100% 100%;
    color: white;
    box-sizing: border-box;
    padding: 0 50rpx;

    .goods_level {
      color: #fff;
      font-size: 24rpx;
      padding: 10rpx 0;
      border-top-right-radius: 20rpx;
      width: 100rpx;
      border-bottom-right-radius: 20rpx;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .goods_info {
      margin-top: 150rpx;
      display: flex;
      /*padding: 0 30rpx 30rpx 30rpx;*/

      .goods-image-bg {
        position: relative;
        background-size: 100% 100%;
        width: 180rpx;
        height: 180rpx;
        display: flex;
        align-items: center;
        justify-content: center;
        margin: 0 20rpx 0 30rpx;
      }

      .goods_image {
        width: 170rpx;
        height: 170rpx;
      }

      .goods_item {
        width: 450rpx;
        display: flex;
        justify-content: space-around;
        flex-direction: column;

        .goods_name {
          width: 100%;
          font-size: 30rpx;
          -webkit-line-clamp: 3;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          overflow: hidden;
        }

        .goods_price_num-box {
          display: flex;
          justify-content: space-between;
          align-items: center;

          .goods_price {
            display: flex;
            align-items: center;
            font-size: 28rpx;

            .gold {
              width: 32rpx;
              margin-left: 10rpx;
            }
          }

          .goods_num {
            color: #ccc;
            font-size: 24rpx;
            margin-right: 40rpx;
          }
        }
      }
    }
  }

  .exchange {
    padding: 0 25rpx;
    font-size: 26rpx;
    color: #999;
    width: 650rpx;
    margin: 30rpx auto;
    border-radius: 5rpx;
  }

  .bottom {
    display: flex;
    justify-content: space-between;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 120rpx;
    align-items: center;
    color: white;

    .bottom_text {
      display: flex;
      align-items: center;
      font-size: 24rpx;
      margin-left: 30rpx;

      .bottom_text_num {
        margin-right: 10rpx;
        font-size: 24rpx;
      }

      .bottom_text_amount {
        font-size: 40rpx;
        margin-right: 10rpx;
        color: #ee5093;
      }

      .gold {
        width: 30rpx;
      }
    }

    .exchange_btn {
      height: 84rpx;
      line-height: 84rpx;
      text-align: center;
      width: 228rpx;
      margin: 0 20rpx;
      font-weight: bold;
      color: #fff;
      font-size: 28rpx;
      background-size: 100% 100%;

      &.none {
        filter: grayscale(1);
      }
    }
  }
}
</style>